const express = require("express")
const path = require("path")

const app = express()

// const env = process.env.NODE_ENV

const PORT = "3001"

app.use(express.json())
app.use(express.urlencoded({ extended: false }))
app.use(express.static(path.join(__dirname, "uploads")))

// 设置模板引擎的路径
app.set("views", path.join(__dirname, "views"))
app.set("view engine", "ejs")

// 引入路由
const userRouter = require("./routes/user")
const blog_message = require("./routes/blog_message")
const blog_timeline = require("./routes/blog_timeline")
const blog_user = require("./routes/blog_user")
const blog_todo = require("./routes/blog_todo")
const blog_file_server = require("./routes/blog_file_server")
const blog_knowledge = require('./routes/blog_knowlege')


const checkTokenMiddleware = require("./middleware/checkTokenMiddleware")

app.use("/api", userRouter)
app.use("/blog/message", checkTokenMiddleware, blog_message)
app.use("/blog/timeline", checkTokenMiddleware, blog_timeline)
app.use("/blog/todo", checkTokenMiddleware, blog_todo)
app.use("/blog/file", checkTokenMiddleware, blog_file_server)
app.use("/blog/knowledge", checkTokenMiddleware, blog_knowledge)
app.use("/blog/user", blog_user)

app.listen(PORT, () => {
  console.log(`Server is running on port ${PORT}`)
})
